/*********************************************************************************************************************
 * COPYRIGHT NOTICE
 * Copyright (c) 2020,逐飞科技
 * All rights reserved.
 * 技术讨论QQ群：一群：179029047(已满)  二群：244861897(已满)  三群：824575535
 *
 * 以下所有内容版权均属逐飞科技所有，未经允许不得用于商业用途，
 * 欢迎各位使用并传播本程序，修改内容时必须保留逐飞科技的版权声明。
 *
 * @file            main
 * @company         成都逐飞科技有限公司
 * @author          逐飞科技(QQ790875685)
 * @version         查看doc内version文件 版本说明
 * @Software        MDK FOR C51 V9.60
 * @Target core     STC8A8K64S4
 * @Taobao          https://seekfree.taobao.com/
 * @date            2020-4-14
 ********************************************************************************************************************/

#include "headfile.h"

uint16 duty = 0;
bit dir = 0;

idata uint16 test_u16, i;
idata float  test_f = 0.25;
idata uint8  test_str[20];
idata uint8  h_str[3], m_str[3], s_str[3];
idata uint8 hour = 8, minute = 38, second = 0;
bit temp_flag;
idata uint32 oldticks, ticks;
idata uint8 x_panada = 10;

#if (1==PRINTF_ENABLE)
extern uint32 sys_clk;
extern uint16 pca_delay_1ms;
#endif

void main()
{
    uint8 gu_i, gu_j;
    DisableGlobalIRQ();
    board_init();
    led_init();
    key_init();
    EnableGlobalIRQ();
#if (1==PRINTF_ENABLE)
    printf ( "sysclk= %ld\r\n", sys_clk );
    printf ( "pca_delay_1ms= %d\r\n", pca_delay_1ms );
#endif

    GU_Init();
    GU_SetPos(0, 0);
//    GU_PutStr6x8(10, 2, "HELLO GU!", GUNOMALCOLORMODE);
//    GU_PutStr8x16(10, 4, "HELLO GU", GUNOMALCOLORMODE);
//    GU_PutChinese ( 10, 0, 1 , GUNOMALCOLORMODE);
//    GU_PutChinese ( 10 + 16 * 1, 0, 2 , GUNOMALCOLORMODE);
//    GU_PutChinese ( 10 + 16 * 2, 0, 3 , GUNOMALCOLORMODE);
//    GU_PutChinese ( 10 + 16 * 3, 0, 4 , GUNOMALCOLORMODE);
//    GU_PutChinese ( 10 + 16 * 4, 0, 5 , GUNOMALCOLORMODE);
//    GU_PutChinese ( 10 + 16 * 5, 0, 6 , GUNOMALCOLORMODE);
//    GU_PutStr20x40(10, 1, "12:34", GUNOMALCOLORMODE);
//    GU_SetPos(0, 0);
//    pca_delay_ms(3000);
    GU_Clear();
//    GU_Draw_BMP(35, 0, 35 + 58, 8, AiThink, GUNOMALCOLORMODE);
//    GU_SetPos(0, 0);
    LED1_OFF;
    LED2_OFF;
    LED3_OFF;
    LED4_OFF;
    // pwm_init(PWM0_P60, 10000, 5000);

    tick_TimerInit();
    oldticks = tick_GetTicks();
    GU_PutStr6x8(42, 0, "2021/08/11 WED", GUNOMALCOLORMODE);
    GU_Draw_BMP(10, 0, 16, 1, icon_bluetooth, GUNOMALCOLORMODE);
    GU_Draw_BMP(20, 0, 26, 1, icon_clock, GUNOMALCOLORMODE);
    GU_Draw_BMP(80, 6, 92, 8, icon_temperature, GUNOMALCOLORMODE);
    GU_Draw_BMP(10, 6, 32, 8, icon_panada, GUNOMALCOLORMODE);
//    gui_DlgDesktopOpen(); //GUI初始窗口/对话框打开之后，开始使用gui_task()调度对话框
    while ( 1 )
    {
        ticks = tick_GetTicks();
        if (ticks - oldticks < 250 )
        {
            //sprintf(test_str, "%02bd:%02bd", hour, minute);
            GU_PutStr20x40(47, 1, ":", GUNOMALCOLORMODE);
        }
        else if (ticks - oldticks > 250 && ticks - oldticks < 500)
        {
            //sprintf(test_str, "%02bd %02bd", hour, minute);
            //printf("tick=%ld,old=%ld\r\n", ticks, oldticks);
            GU_PutStr20x40(47, 1, " ", GUNOMALCOLORMODE);
        }
        else if (ticks - oldticks >= 500)
        {
            oldticks = ticks;
            if (++x_panada > 50)
                x_panada = 10;
            if (++second >= 60)
            {
                second = 0;
                if (++minute >= 60)
                {
                    minute = 0;
                    if (++hour >= 24)
                        hour = 0;
                }
            }
            sprintf(s_str, "%02bd", second);
            GU_PutStr6x8(109, 4, s_str, GUNOMALCOLORMODE);
            sprintf(h_str, "%02bd", hour);
            GU_PutStr20x40(7, 1, h_str, GUNOMALCOLORMODE);
            sprintf(m_str, "%02bd", minute);
            GU_PutStr20x40(65, 1, m_str, GUNOMALCOLORMODE);

        }
        if ((second % 10 ) < 5)
        {
            GU_PutStr8x16(96, 6, "25.6", GUNOMALCOLORMODE);
        }
        if ((second % 10 ) >= 5)
        {
            GU_PutStr8x16(96, 6, " 65%", GUNOMALCOLORMODE);
        }
        GU_RecClear(x_panada - 2, 6, 72, 8);
        switch (second % 3)
        {
        case 0:
            GU_Draw_BMP(x_panada, 6, x_panada + 22, 8, icon_panada, GUNOMALCOLORMODE);
            break;
        case 1:
            GU_Draw_BMP(x_panada, 6, x_panada + 22, 8, &icon_panada[44], GUNOMALCOLORMODE);
            break;
        case 2:
            GU_Draw_BMP(x_panada, 6, x_panada + 22, 8, &icon_panada[88], GUNOMALCOLORMODE);
            break;
        default:
            break;
        }
        //GU_Draw_BMP(10, 6, 32, 8, icon_panada, GUNOMALCOLORMODE);
        pca_delay_ms ( 50 );
//        pwm_duty(PWM0_P60, duty);
//        pca_delay_ms ( 50 );
//        if (!dir)
//        {
//            duty += 50;
//            if (duty >= PWM_DUTY_MAX)
//            {
//                dir = 1;
//                duty = PWM_DUTY_MAX;
//            }
//        }
//        else
//        {
//            duty -= 50;
//            if (duty <= 70)
//            {
//                dir = 0;
//                duty = 0;
//            }
//        }
//        key_Task();
//        gui_Task();

    }
}












